/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.team3309.beta.commands;

import edu.wpi.first.wpilibj.CANJaguar;
import edu.wpi.first.wpilibj.CANJaguar.ControlMode;
import edu.wpi.first.wpilibj.can.CANTimeoutException;
import edu.wpi.first.wpilibj.command.Command;
import org.team3309.beta.subsystems.Arm;

/**
 *
 * @author Vincente
 */
public class SetAngle extends Command {

    private CANJaguar jag;
    private Arm arm;
    private double pos;
    private double OFFSET = 0;
    private double desiredAngle = 180;


    public SetAngle() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        arm = Arm.getInstance();
        requires(arm);
    }

    // Called just before this Command runs the first time
    protected void initialize() {

        this.jag = arm.getJaguar();
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        arm.changeControlMode(CANJaguar.ControlMode.kPosition);
        try{
            jag.setX(desiredAngle);
        }catch (CANTimeoutException ex){
            ex.printStackTrace();
        }
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return false;
    }

    // Called once after isFinished returns true
    protected void end() {
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
    }

    public double getAngle(){
                double ret = 0;
        try{
            ret = jag.getPosition();
        }catch (CANTimeoutException ex){
            ex.printStackTrace();
        }
        ret-=OFFSET;
        return ret;
    }
}